'use strict'
let fs = require('fs')

function getTemplateInfo(name) {
  fs.readdirSync(__dirname + '/' + name).forEach(function(file) {
    if (/^\d+.js$/.test(file)) {
      var templateInfo = require('./' + name + '/' + file)
      for (let i in templateInfo) {
        let templateId = parseInt(i.split('_')[1])
        exports[name][templateId] = templateInfo[i]
        exports[name][templateId]['templateId'] = templateId
        exports[name][templateId]['type'] = Math.floor(templateId / 10000)
        if (templateInfo[i].name) {
          propName[templateId] = templateInfo[i].name
        }
        exports.total[templateId] = templateInfo[i]
      }
    }
  })
}

//所有模板信息
let total = {}
let propName = {} //发送给客户端的信息 id => name
exports.total = total
exports.totalConfig = total
exports.propName = propName

//角色模板信息
let character = {}
exports.character = character
getTemplateInfo('character')

//装备模板信息
let equipment = {}
exports.equipment = equipment
getTemplateInfo('equipment')


//道具模板信息
let prop = {}
exports.prop = prop
getTemplateInfo('prop')


//公共场景模板信息
let scene = {}
exports.scene = scene
getTemplateInfo('scene')

//其他配置
let other = {}
exports.other = other
getTemplateInfo('other')


//怪物模板信息
let monster = {}
exports.monster = monster
getTemplateInfo('monster')


//强化配置
let strengthen = {}
exports.strengthen = strengthen
getTemplateInfo('strengthen')

//强化配置
let skill = {}
exports.skill = skill
getTemplateInfo('skill')


//秘境场景
let lattice = {}
exports.lattice = lattice
getTemplateInfo('lattice')

//秘境地图
let secretMap = {}
exports.secretMap = secretMap
getTemplateInfo('secretMap')

//魔窟
let devilCave = {}
exports.devilCave = devilCave
getTemplateInfo('devilCave')

//前缀属性
let prefixAttri = {}
exports.prefixAttri = prefixAttri
getTemplateInfo('prefixAttri')

//前缀属性
let alchemy = {}
exports.alchemy = alchemy
getTemplateInfo('alchemy')
